package com.sunlg.smarthome.ui.plant;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sunlg.smarthome.R;
import com.sunlg.smarthome.base.BaseFragment;
import com.sunlg.smarthome.contract.LoadRainObserverContract;
import com.sunlg.smarthome.contract.presenter.LoadRainObserverPresenter;
import com.sunlg.smarthome.data.entity.RainObserver;

public class RainObserverFragment extends BaseFragment
        implements LoadRainObserverContract.View{

    private ImageView ivRain;
    private TextView tvDesc;

    private LoadRainObserverContract.Presenter presenter;

    public RainObserverFragment() {

    }


    @Override
    protected int getLayoutResourceId() {
        return R.layout.fragment_rain_observer;
    }

    @Override
    protected void init() {
        presenter = new LoadRainObserverPresenter();
        presenter.attachView(this);
    }

    @Override
    protected void initView(View view) {
        ivRain = (ImageView)view.findViewById(R.id.iv_rain);
        tvDesc = (TextView)view.findViewById(R.id.tv_desc);
    }

    @Override
    public void onStart() {
        super.onStart();
        presenter.loadRainObserver();
    }

    @Override
    public void loadRainObserverSuccess(RainObserver rainObserver) {
        if(rainObserver.getStatus() > 0){
            if(ivRain.getVisibility() != View.VISIBLE){
                ivRain.setVisibility(View.VISIBLE);
            }
            tvDesc.setText("有雨， 注意及时收好衣服，关好门窗");
        }else {
            if(ivRain.getVisibility() == View.VISIBLE){
                ivRain.setVisibility(View.INVISIBLE);
            }
            tvDesc.setText("无雨");
        }
    }

    @Override
    public void showNoDevice() {
        tvDesc.setText("没有设备");
    }

    @Override
    public void showError(String msg) {

    }
}
